<?php
namespace cms\modules\v1\controllers;

use cms\modules\v1\models\access\ModuleActions;
use cms\modules\v1\models\versions\Versions;
use common\models\Functions;
use Yii;

/**
 * Default controller for the `v1` module
 */
class VersionsController extends DefaultController
{

    public $modelClass = 'cms\modules\v1\models\v\Notice';

    //get方式
    public function actionList($page = 1, $size = 20){
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isGet) {
            return (new Versions())->getListData($page, $size);
        }
    }

    public function actionAddEdit($id = 0) {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        $model = new Versions();
        if (Yii::$app->request->isGet) {
            return $model->getInfo($id);
        }

        if (Yii::$app->request->isPost) {
            $model->setScenario('addEdit');
            if ($model->load(Yii::$app->request->post(), '')) {
                return $model->addEdit();
            }
        }
    }

}
